package com.ymatou.iapi.productmanager.testcase;

import com.ymatou.iapi.productmanager.parameter.SetAlhProductRebateRateBean;
import com.ymatou.iapi.productmanager.parameter.product.AddSellerProductRequest;
import com.ymatou.iapi.productmanager.service.SetAlhProductRebateRateCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.ProductManagerCallServiceV3;
import com.ymttest.utils.EnvSetup;
import org.junit.*;
import org.junit.experimental.categories.Category;

import java.math.BigDecimal;
/**
*设置费率
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_SetAlhProductRebateRate{
	private static SetAlhProductRebateRateBean setalhproductrebaterateBean;
	private static SetAlhProductRebateRateCall setalhproductrebaterateCall;
	private static int sellerId = Integer.parseInt(EnvSetup.getData("productsellerid"));
	private static String sellerName = EnvSetup.getData("productsellername");
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("设置费率");
	}

	@Before
	public void caseUp() {
		setalhproductrebaterateBean=new SetAlhProductRebateRateBean();
		setalhproductrebaterateCall=new SetAlhProductRebateRateCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(setalhproductrebaterateCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetAlhProductRebateRate_001() {
		Logger.start(true,"信息正确,设置成功");
		try {
			AddSellerProductRequest addProdReq = ProductManagerCallServiceV3.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV3.AddSellerProduct(addProdReq);
			setalhproductrebaterateBean.setUserId(sellerId);
			setalhproductrebaterateBean.setProductId(productId);
			setalhproductrebaterateBean.setRebateRate(new BigDecimal(0.10));
			setalhproductrebaterateCall.setData(setalhproductrebaterateBean);
			setalhproductrebaterateCall.callService();
			Logger.verifyEquals("200", setalhproductrebaterateCall.getJsonObject().get("Code").getAsString(), "判断code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetAlhProductRebateRate_002() {
		Logger.start(true,"用户id错误,设置失败");
		try {
			AddSellerProductRequest addProdReq = ProductManagerCallServiceV3.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV3.AddSellerProduct(addProdReq);
			setalhproductrebaterateBean.setUserId(1113312);
			setalhproductrebaterateBean.setProductId(productId);
			setalhproductrebaterateBean.setRebateRate(new BigDecimal(0.10));
			setalhproductrebaterateCall.setData(setalhproductrebaterateBean);
			setalhproductrebaterateCall.callService();
			Logger.verifyEquals("201", setalhproductrebaterateCall.getJsonObject().get("Code").getAsString(), "判断code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetAlhProductRebateRate_003() {
		Logger.start(true,"费率过大,设置失败");
		try {
			AddSellerProductRequest addProdReq = ProductManagerCallServiceV3.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV3.AddSellerProduct(addProdReq);
			setalhproductrebaterateBean.setUserId(sellerId);
			setalhproductrebaterateBean.setProductId(productId);
			setalhproductrebaterateBean.setRebateRate(new BigDecimal(5));
			setalhproductrebaterateCall.setData(setalhproductrebaterateBean);
			setalhproductrebaterateCall.callService();
			Logger.verifyEquals("500", setalhproductrebaterateCall.getJsonObject().get("Code").getAsString(), "判断code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetAlhProductRebateRate_004() {
		Logger.start(true,"费率为0,设置失败");
		try {
			AddSellerProductRequest addProdReq = ProductManagerCallServiceV3.initAddSellerProductRequest(sellerId);
			String productId = ProductManagerCallServiceV3.AddSellerProduct(addProdReq);
			setalhproductrebaterateBean.setUserId(sellerId);
			setalhproductrebaterateBean.setProductId(productId);
			setalhproductrebaterateBean.setRebateRate(new BigDecimal(0));
			setalhproductrebaterateCall.setData(setalhproductrebaterateBean);
			setalhproductrebaterateCall.callService();
			Logger.verifyEquals("500", setalhproductrebaterateCall.getJsonObject().get("Code").getAsString(), "判断code");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

}